package com.weberror.frontendmonitoring.performancedata.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.weberror.frontendmonitoring.performancedata.entity.Performancedata;
import com.weberror.frontendmonitoring.performancedata.service.PerformancedataService;
import com.weberror.frontendmonitoring.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 性能数据(Performancedata)表控制层
 *
 * @author cnxym
 * @since 2022-08-17 19:35:45
 */
@RestController
@RequestMapping("performance")
public class PerformancedataController {
    /**
     * 服务对象
     */
    @Autowired
    private PerformancedataService performancedataService;

    /**
     * 分页查询所有数据
     *
     * @param page            分页对象
     * @param performancedata 查询实体
     * @return 所有数据
     */
    @GetMapping
    public R selectAll(Page<Performancedata> page, Performancedata performancedata) {
        return  R.OK().data("performancedata", performancedataService.page(page, new QueryWrapper<>(performancedata)));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public R selectOne(@PathVariable Integer id) {

        return  R.OK().data("performancedata", performancedataService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param performancedata 实体对象
     * @return 新增结果
     */
    @PostMapping
    public R insert(@RequestBody Performancedata performancedata) {
        return  R.OK().data("performancedata", performancedataService.save(performancedata));
    }


}

